﻿#include "mypushbutton.h"
#include<QDebug>
#include<QPropertyAnimation>
#include<QLabel>
//MyPushButton::MyPushButton(QWidget *parent) : QPushButton(parent)
//{

//}
//尝试用函数获取bbtntxt 但是失败了 只能这样搞
MyPushButton:: MyPushButton(QString normalImg,QString bbtntxt,QString pressImg){
    this->normalImagPath=normalImg;
    this->pressImagPath=pressImg;
    this->btntxt=bbtntxt;
    QPixmap pix;
    bool ret=pix.load(normalImg);
    if(!ret){
        qDebug()<<"图片加载失败";
        return;
    }
    //文字设置标题
    QLabel *label=new QLabel;
    label->setParent(this);
    QFont font;
    font.setFamily("华文新魏");
    font.setPointSize(10);
    label->setFont(font);
    //qDebug()<<btntxt;
    label->setText(btntxt);
    label->setGeometry(QRect(70,45,120,50));
    //设置图片固定大小
    this->setFixedSize(220,150);
    //设置不规则图片样式  矩形嗷
    this->setStyleSheet("QPushButton{border:0px;}");
    //设置图标
    this->setIcon(pix);
    //设置图标大小
    this->setIconSize(QSize(220,150));
}
MyPushButton::MyPushButton(){//默认构造

}

void MyPushButton::zoom1(){
    //创建动态对象
    QPropertyAnimation * animation=new QPropertyAnimation(this,"geometry");
    //设置动画时间间隔
    animation->setDuration(100);
    //起始位置
    animation->setStartValue(QRect(this->x(),this->y(),this->width(),this->height()));
    //结束位置
    animation->setEndValue(QRect(this->x(),this->y()+10,this->width(),this->height()));

    //设置弹跳曲线
    animation->setEasingCurve(QEasingCurve::OutBounce);
    //执行动画
    animation->start();


}
void MyPushButton::zoom2(){
    //创建动态对象
    QPropertyAnimation * animation=new QPropertyAnimation(this,"geometry");
    //设置动画时间间隔
    animation->setDuration(100);
    //起始位置
    animation->setStartValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
    //结束位置
    animation->setEndValue(QRect(this->x(),this->y(),this->width(),this->height()));

    //设置弹跳曲线
    animation->setEasingCurve(QEasingCurve::OutBounce);
    //执行动画
    animation->start();
}

